package com.yuntsg.nnsfcp.controller.front;


import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yuntsg.nnsfcp.common.beans.ResultBean;
import com.yuntsg.nnsfcp.common.utils.CheckUtil;
import com.yuntsg.nnsfcp.common.utils.StringUtil;
import com.yuntsg.nnsfcp.entity.NsfcSearchVo;
import com.yuntsg.nnsfcp.front.entity.Nsfc;
import com.yuntsg.nnsfcp.front.mapper.NsfcMapper;
import com.yuntsg.nnsfcp.service.CommonService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/nsfc")
//@Api(tags = "基金检索", description = "基金检索")
@SuppressWarnings(value = "all")
@Slf4j
public class NsfcController {

    //统一检索的jar包
    public static String RESTURL = "http://10.1.1.11:65213/";

    @Resource
    CommonService commonService;

    @Resource
    NsfcMapper nsfcMapper;

    //    @ApiOperation(value = "1作者检索_查看文章,输入作者名字(选择一二级单位),查看对应文章,可能是一个或多个同名作者所写的所有文章")
    @PostMapping(value = "search")
    public ResultBean<Object> auth_article(@RequestBody NsfcSearchVo nsfcSearchVo) throws Exception {
        String result = HttpUtil.post(RESTURL + "nsfc/search2", JSONObject.toJSONString(nsfcSearchVo));
        return JSONObject.parseObject(result, ResultBean.class);
    }

    //    @ApiOperation(value = "2根据检索记过页面记下来获取详情页")
    @GetMapping(value = "search-detail")
//    @ApiImplicitParam(value = "基金号", name = "nfscno")
    public ResultBean<Object> nsfcDetail(String nfscno) throws Exception {
        CheckUtil.check(StringUtil.isNotNull(nfscno), "基金号不能空");
        List<Nsfc> var3 = nsfcMapper.selectList(new QueryWrapper<Nsfc>().eq("id", nfscno));
        if (var3.size() > 0) {
            Nsfc nsfc = var3.get(0);
            commonService.dealSpNsfc(nsfc);
            return new ResultBean<>(nsfc);
        } else {
            CheckUtil.check(false, "检索错误");
        }

        return new ResultBean<>();
    }
}


















































